package com.jiehoo.utils.io.filter;

import java.io.*;

public abstract class CombineFileFilter extends
		javax.swing.filechooser.FileFilter implements java.io.FileFilter {
	public static final int IOLIST = 0;
	public static final int SWING = 1;
	protected int type;

	public CombineFileFilter() {
		this(SWING);
	}

	public CombineFileFilter(int type) {
		this.type = type;
	}

	public boolean accept(File file) {
		switch (type) {
		case IOLIST:
			return acceptFile(file);
		case SWING:
			if (includeDirectoryForSwing() && file.isDirectory()) {
				return true;
			}
			return acceptFile(file);
		default:
			if (includeDirectoryForSwing() && file.isDirectory()) {
				return true;
			}
			return acceptFile(file);
		}
	}

	public boolean accept(File dir, String name) {
		return acceptFile(new File(name));
	}

	protected abstract boolean acceptFile(File file);

	protected boolean includeDirectoryForSwing() {
		return true;
	}

}